<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>ProgramStepCheck</title>
	<link href="../../../webjar/bootstrap/3.3.7-1/css/bootstrap.min.css" rel="stylesheet">
	<link href="../../../webjar/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="../../../webjar/css/mystyle.css" rel="stylesheet">
	<link rel="stylesheet" media="all" type="text/css" href="CSS/workflow.css" />

	<script src="../../../webjar/jquery/3.1.1/jquery.min.js"></script>
    <script src="../../../webjar/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
    <script src="../../../webjar/bootstrap-table/bootstrap-table.min.js"></script>

</head>
<body>
	<form class="form-horizontal" role="form" style="padding:15px;">
		<div class="form-group" style="margin-bottom:5px;">
	        <div class="col-xs-9">
	            <input type="text" class="form-control" id="txtPSCcontent" placeholder="请输入一段文字描述程序信息">
	        </div>
	        <div class="col-xs-3">
	        	<button type="button" id="PSCSearch" class="btn btn-custom" style="width:100%;">搜索</button>
	        </div>
		</div>
		<div class="form-group" style="padding:15px">
			<div class="bootstrap-table table">
				<div class="table-responsive">
					<!--<table id="PSCresultTable" data-toggle="table" data-click-to-select="true" data-striped="true" data-height="150" data-row-style="rowStyle" data-cell-style="cellStyle" data-unique-id="id">
						<thead>
							<tr>
                    			<th data-field="state" data-radio="true"></th>
                            	<th data-field="id" data-visible="false"></th>
                            	<th data-field="code">代码</th>
                            	<th data-field="name">名称</th>
                            	<th data-field="version">版本</th>
                    		</tr>
						</thead>
					</table>-->

					<table id="PSCresultTable" class="bootstrap-table table"
						   data-toggle="table"
						   data-click-to-select="true"
						   data-striped="true"
						   data-row-style="rowStyle"
						   data-cell-style="cellStyle"
					       data-height="150">
						<thead>
						<tr>
							<th data-field="state" data-radio="true"></th>
							<th data-field="id" data-visible="false"></th>
							<th data-field="code">代码</th>
							<th data-field="name">名称</th>
							<th data-field="version">类型</th>
						</thead>
					</table>
				</div>
			</div>
		</div>

		<div class="form-group">
			<label for="Step_Number" class="col-xs-4 control-label" style="text-align:center">步骤序号：</label>
			<div class="col-xs-8">
				<input type="text" class="form-control" id="Step_Number" placeholder="请输入步骤序号">
			</div>
		</div>

		<div class="form-group" style = "margin-bottom: 0px">
	        <div class="col-xs-6" style="text-align: right">
	            <button type="button" id="PSCconfirm" class="btn btn-info">确定</button>
	        </div>
			<div class="col-xs-6" style="text-align: left">
				<button type="button" id="PSCancel" class="btn btn-info">取消</button>
			</div>
	    </div>
	</form>
	<script type="text/javascript">
		var wfcode, wfname, version, wfid, checkSig1 = false;
		$(function(){
			if(workFlowId){
				initFunctions();
			}
		});

		function initFunctions(){
			'use strict';
			//加载表格数据
			var StepCheckUrl = serverPath + "craftProcessSteps/findCraftProcessStep";
			var datas = {'str':"",'statusId':3};
			$.ajax({
				url: StepCheckUrl,
				data: datas,
				xhrFields:{ withCredentials:true},
				dataType: "json",
				//async: false,
				success: function (result) {
					var data = result.data;
					$("#PSCresultTable").bootstrapTable('load', data);
				},
				error: function () {
					alert('未能加载步骤信息');
				}
			});

			//表格事件处理
			$('#PSCresultTable').on('check.bs.table', function (e, row){
				//拿到行选中的数据
				wfcode = row["code"];
				wfname = row["name"];
				version = row["version"];
				wfid = row["id"];
				checkSig1 = true;		//确定表格中已经选择
			});

			//确认保存按钮
			$('#PSCconfirm').on('click', function(){
				var ckResult = CheckEmptyTips();
				if(ckResult == false) return;

				var addObject = getObjectById(ActiveId);
				if(!addObject || addObject.objType != "Task"){
					//添加矩形
					drawRectangleCmd();
				}
				selectStepInfo(wfcode, wfname, version, wfid, $('#Step_Number').val());
			});

			//查找按钮事件
			$('#PSCSearch').on('click',function(){
				var $val = $('#txtPSCcontent').val();
				findStepData($val);
			});
		}

		//查找数据按钮功能
		function findStepData(str){
			var checkDatasUrl = serverPath + "craftProcessSteps/findCraftProcessStep";
			var datas = {'str':str,'statusId':3};
			ibcpAjax.Select(checkDatasUrl,datas,true,function(result){
				var data = result.data;
				$('#PSCresultTable').bootstrapTable('load', data);
				if(data.length >0) {
					//设置选中行
					$('#PSCresultTable').bootstrapTable('check', 0);
				}
			});
		}

		//数据非空验证
		function CheckEmptyTips(){
			'use strict';
			var check = true;
			if(checkSig1 == false){
				ibcpLayer.ShowTips('请选择步骤！',$('#PSCresultTable'));
				check = false;
			}
			if($('#Step_Number').val() == ""){
				ibcpLayer.ShowTips('请填写序号！', $('#Step_Number'));
				check = false;
			}
			return check;
		}

	</script>
</body>
</html>